package vip.liux.gateway.filters.decrypt;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;

@Configuration
@EnableConfigurationProperties(AppKeyRepositoryProperties.class)
public class AppKeyRepositoryAutoConfiguration {

    @Bean
    @ConditionalOnProperty(name = "gateway.app-key-repository.type", havingValue = "memory", matchIfMissing = true)
    public AppKeyRepository memoryAppKeyRepository(AppKeyRepositoryProperties properties) {
        return new AppKeyMemoryRepository(properties);
    }

    @Bean
    @ConditionalOnProperty(name = "gateway.app-key-repository.type", havingValue = "redis-hash")
    public AppKeyRepository redisAppKeyRepository(ReactiveStringRedisTemplate reactiveStringRedisTemplate) {
        return new AppKeyRedisRepository(reactiveStringRedisTemplate);
    }
}